package com.example.demo.service.impl;

import java.util.Date;
import java.util.List;

import com.example.demo.utils.PageResult;
import com.example.demo.utils.PageUtils;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.example.demo.mapper.BannerMapper;
import com.example.demo.entity.Banner;
import com.example.demo.service.IBannerService;

/**
 * bannerService业务层处理
 * 
 * @author ruoyi
 * @date 2025-03-27
 */
@Service
public class BannerServiceImpl implements IBannerService 
{
    @Autowired
    private BannerMapper bannerMapper;

    /**
     * 查询banner
     * 
     * @param id banner主键
     * @return banner
     */
    @Override
    public Banner selectBannerById(Long id)
    {
        return bannerMapper.selectBannerById(id);
    }

    /**
     * 查询banner列表
     * 
     * @param banner banner
     * @return banner
     */
    @Override
    public List<Banner> selectBannerList(Banner banner)
    {
        return bannerMapper.selectBannerList(banner);
    }

    /**
     * 新增banner
     * 
     * @param banner banner
     * @return 结果
     */
    @Override
    public int insertBanner(Banner banner)
    {
        banner.setCreateTime(new Date());
        return bannerMapper.insertBanner(banner);
    }

    /**
     * 修改banner
     * 
     * @param banner banner
     * @return 结果
     */
    @Override
    public int updateBanner(Banner banner)
    {
        banner.setUpdateTime(new Date());
        return bannerMapper.updateBanner(banner);
    }

    /**
     * 批量删除banner
     * 
     * @param ids 需要删除的banner主键
     * @return 结果
     */
    @Override
    public int deleteBannerByIds(Long[] ids)
    {
        return bannerMapper.deleteBannerByIds(ids);
    }

    /**
     * 删除banner信息
     * 
     * @param id banner主键
     * @return 结果
     */
    @Override
    public int deleteBannerById(Long id)
    {
        return bannerMapper.deleteBannerById(id);
    }

    @Override
    public PageResult selectBannersList(Banner banner, int pageNum, int pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<Banner> list=bannerMapper.selectBannerList(banner);
        System.out.println(list.size());
        PageInfo<Banner>pageInfo=new PageInfo<>(list);
        PageResult pageResult= PageUtils.getPageResult(pageInfo);
        return pageResult;
    }
}
